package com.thwj.project.biz.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.thwj.common.annotation.Log;
import com.thwj.common.core.controller.BaseController;
import com.thwj.common.core.domain.AjaxResult;
import com.thwj.common.core.page.TableDataInfo;
import com.thwj.common.enums.BusinessType;
import com.thwj.common.utils.poi.ExcelUtil;
import com.thwj.project.biz.domain.ActivitySignup;
import com.thwj.project.biz.service.IActivitySignupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 活动报名Controller
 *
 * @author generate
 * @date 2023-06-16
 */
@RestController
@RequestMapping("/biz/signup")
public class ActivitySignupController extends BaseController {
    @Autowired
    private IActivitySignupService activitySignupService;
/**
 * 查询活动报名列表
 */
@PreAuthorize("@ss.hasPermi('biz:signup:list')")
@GetMapping("/list")
    public TableDataInfo list(ActivitySignup activitySignup) {
        startPage();
        List<ActivitySignup> list = activitySignupService.getBaseMapper().selectList(new QueryWrapper<>(activitySignup));
        return getDataTable(list,((Page)list).getTotal());
    }

    /**
     * 导出活动报名列表
     */
    @PreAuthorize("@ss.hasPermi('biz:signup:export')")
    @Log(title = "活动报名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ActivitySignup activitySignup) {
        List<ActivitySignup> list = activitySignupService.list(new QueryWrapper<>(activitySignup));
        ExcelUtil<ActivitySignup> util = new ExcelUtil<ActivitySignup>(ActivitySignup. class);
        util.exportExcel(response, list, "活动报名数据");
    }

    /**
     * 获取活动报名详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:signup:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(activitySignupService.getById(id));
    }

    /**
     * 新增活动报名
     */
    @PreAuthorize("@ss.hasPermi('biz:signup:add')")
    @Log(title = "活动报名", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActivitySignup activitySignup) {
        return toAjax(activitySignupService.save(activitySignup));
    }

    /**
     * 修改活动报名
     */
    @PreAuthorize("@ss.hasPermi('biz:signup:edit')")
    @Log(title = "活动报名", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ActivitySignup activitySignup) {
        return toAjax(activitySignupService.updateById(activitySignup));
    }

    /**
     * 取消活动报名
     */
    @PreAuthorize("@ss.hasPermi('biz:signup:edit')")
    @Log(title = "取消活动报名", businessType = BusinessType.UPDATE)
    @PostMapping("cancelSignUp")
    public AjaxResult cancelSignUp(@RequestBody ActivitySignup activitySignup) {
        return toAjax(activitySignupService.cancelSignUp(activitySignup));
    }

    /**
     * 删除活动报名
     */
    @PreAuthorize("@ss.hasPermi('biz:signup:remove')")
    @Log(title = "活动报名", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(activitySignupService.removeByIds(Arrays.asList(ids)));
    }
}
